<?php

use yii\web\View;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\assets\WechatAsset;

$this->title = '创建二维码';
$this->params['breadcrumbs'][] = ['label' => '二维码', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="qrcode-create">

    <h1><?= Html::encode($this->title) ?></h1>

    <div class="qrcode-form">

        <?php $form = ActiveForm::begin([
            'action' => '',
            'method' => 'post',
            'options' => [
                'class' => 'form'
            ]
        ]); ?>

        <?= $form->field($model, 'type')->radioList([1 => 'QR_SCENE[临时的整型]', 2 => 'QR_STR_SCENE[临时的字符串]', 3 => 'QR_LIMIT_SCENE[永久的整型]', 4 => 'QR_LIMIT_STR_SCENE[永久的字符串]']) ?>

        <?= $form->field($model, 'scene_id', ['options' => ['style' => 'display:none']])->textInput(['maxlength' => true, 'readonly' => 'readonly', 'placeholder' => $scene_id, 'value' => $scene_id]) ?>

        <?= $form->field($model, 'scene_str', ['options' => ['style' => 'display:none']])->textInput(['maxlength' => true]) ?>

        <?= $form->field($model, 'expire_seconds', ['options' => ['style' => 'display:none']])->textInput() ?>

        <div class="form-group">
            <?= Html::submitButton('创建', ['class' => 'btn btn-success']) ?>
        </div>

        <?php ActiveForm::end(); ?>

    </div>

</div>
<?php

$js = <<<JS
$(document).ready(function(){
    var type = $("[name='Qrcode[type]']:checked").val(); // 1 - 临时的整型 2 - 临时的字符串 3 - 永久的整型 4 - 永久的字符串
    showfield(type);
});
    
$("#qrcode-type [type='radio']").click(function(){
    $(".field-qrcode-scene_id").hide()
    $(".field-qrcode-scene_str").hide()
    $(".field-qrcode-expire_seconds").hide()
    $(".field-qrcode-scene_id input").val('');
    $(".field-qrcode-scene_str input").val('');
    $(".field-qrcode-expire_seconds input").val('');
    var type = this.value; // 1 - 临时的整型 2 - 临时的字符串 3 - 永久的整型 4 - 永久的字符串
    showfield(type);
});

function showfield(type)
{
    if (type == 1) {
        $(".field-qrcode-scene_id").show();
        $(".field-qrcode-expire_seconds").show();
    } else if (type == 2) {
        $(".field-qrcode-scene_str").show();
        $(".field-qrcode-expire_seconds").show();
    } else if (type == 3) {
        $(".field-qrcode-scene_id").show();
    } else if (type == 4) {
        $(".field-qrcode-scene_str").show();
    } else {
        console.log('error');
    }
}
JS;

$this->registerJs($js, View::POS_END);

?>
